const BaseIpcHandler = require('../BaseIpcHandler');
const { checkDirectoryExists } = require('../../utils/fileUtils');

class IsDirectoryExistsHandler extends BaseIpcHandler {
    async handle(event, params) {
        // 解析参数
        // console.log('>> IsDirectoryExistsHandler params = ', params);
        const directory = params.directory;

        // 业务逻辑
        const isExists = await checkDirectoryExists(directory);
        let result = { code: 0, msg: isExists };

        // 返回结果
        if (event.from === 'localserver') {
            event.resp.send(result);
        } else {
            return result;
        }
    }
}

module.exports = IsDirectoryExistsHandler;
